/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2022-2022. All rights reserved.
 *
 */

import { isWindows } from '@ohos/hvigor';

import { ProjectModel } from '../../model/project/project-model.js';
import { ProjectModelImpl } from '../../model/project/project-model-impl.js';
import { OhosLogger } from '../../utils/log/ohos-logger.js';

import { InspectionI } from './inspection-i.js';

export class ProjectInspection implements InspectionI {
  private _log: OhosLogger = OhosLogger.getLogger('Inspection');
  private readonly projectModel: ProjectModelImpl;

  constructor(projectModel: ProjectModel) {
    this.projectModel = projectModel as ProjectModelImpl;
  }

  doInspection(): InspectionI {
    this.projectPathInspection();
    return this;
  }

  projectPathInspection() {
    const cwd: string = process.cwd();
    const reg = isWindows() ? /(([A-z]):)(\\[a-zA-Z0-9-_.()\s@]+)*(\\?)$/ : /^(\/([a-zA-Z0-9-_.()\s@]+))+(\/?)$/;
    if (!reg.test(cwd)) {
      this._log._buildError('Invalid project path.')._detail('Please move the project to a valid path')._record();
    }
  }

  exitOnError() {
    this._log._printAllExit();
  }
}
